package org.mechanic.exception;

import java.io.Serializable;

/**
 * @ClassName: WxError
 * @Description: 微信错误码说明，请阅读： <a href="http://mp.weixin.qq.com/wiki/10/6380dc743053a91c544ffd2b7c959166.html">全局返回码说明</a>
 * @date 2016年11月4日 上午11:50:45
 */
public class WechatError implements Serializable {

    private static final long serialVersionUID = 7869786563361406291L;

    private int errorCode;

    private String errorMsg;

    private String json;

    public static Builder newBuilder() {
        return new Builder();
    }

    public int getErrorCode() {
        return this.errorCode;
    }

    public void setErrorCode(int errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMsg() {
        return this.errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public String getJson() {
        return this.json;
    }

    public void setJson(String json) {
        this.json = json;
    }

    @Override
    public String toString() {
        if (this.json != null) {
            return this.json;
        }
        return "错误: Code=" + this.errorCode + ", Msg=" + this.errorMsg;
    }

    public static class Builder {
        private int errorCode;
        private String errorMsg;

        public Builder setErrorCode(int errorCode) {
            this.errorCode = errorCode;
            return this;
        }

        public Builder setErrorMsg(String errorMsg) {
            this.errorMsg = errorMsg;
            return this;
        }

        public WechatError build() {
            WechatError wxError = new WechatError();
            wxError.setErrorCode(this.errorCode);
            wxError.setErrorMsg(this.errorMsg);
            return wxError;
        }

    }
}
